<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">卡权益管理</ui:define>
    <ui:define name="content">
        <h:form>
            <p:dialog id="addPrivilege" rendered="#{galaxyCardPrivilegeBean.addingPrivilege != null}"
                      header="卡权益添加" position="center" widgetVar="addPrivilege" modal="true" width="85%"
                      height="90%" responsive="true" footer="权益类型创建后将无法修改，目前只针对跳转链接类型的权益提供直接添加, 跳转链接中可通过包括如下字符串($...)达到动态替换相应参数的目的：[$cardInfoId:用户卡id,$orderId:订单id,$businessId:业务id,$userId:用户id,$cardNo:用户卡号,$phoneNumber:用户手机号,$privilegeInfoId:用户卡权益id,$token:用户ACCESS_TOKEN]">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="addPrivilegeType" value="权益分类"/>
                    <p:selectOneMenu id="addPrivilegeType" value="#{galaxyCardPrivilegeBean.addingPrivilege.privilegeType}" >
                        <f:selectItem itemLabel="请选择" itemValue="" noSelectionOption="true"/>
                        <f:selectItems value="#{galaxyCardPrivilegeBean.privilegeTypeList}"/>
                    </p:selectOneMenu>
                    <p:outputLabel for="addPrivilegeCode" value="权益类型"/>
                    <p:selectOneMenu id="addPrivilegeCode" value="#{galaxyCardPrivilegeBean.addingPrivilege.code}">
                        <p:ajax event="change" process="addPrivilege" update="addPrivilege" oncomplete="PF('addPrivilege').show()"/>
                        <f:selectItem itemLabel="请选择" itemValue="" noSelectionOption="true"/>
                        <f:selectItems value="#{galaxyCardPrivilegeBean.privilegeCodeList}"/>
                    </p:selectOneMenu>
                    <p:outputLabel for="addPrivilegeName" value="权益配置"/>
                    <p:inputText id="addPrivilegeConfig" value="#{galaxyCardPrivilegeBean.addingPrivilege.config}" style="width:100%"/>

                    <p:outputLabel for="addPrivilegeName" value="权益名称"/>
                    <p:inputText id="addPrivilegeName" value="#{galaxyCardPrivilegeBean.addingPrivilege.name}" style="width:100%"/>
                    <p:outputLabel for="addPrivilegeProjectName" value="权益项目"/>
                    <p:inputText id="addPrivilegeProjectName" value="#{galaxyCardPrivilegeBean.addingPrivilege.projectName}" style="width:100%"/>
                    <p:outputLabel for="addPrivilegeIconUrl" value="权益图标"/>
                    <p:inputText id="addPrivilegeIconUrl" value="#{galaxyCardPrivilegeBean.addingPrivilege.iconUrl}" style="width:100%"/>

                    <p:outputLabel for="status1Show" value="显示状态" rendered="#{galaxyCardPrivilegeBean.isDefaultBusiness()}"/>
                    <p:inputText id="status1Show" value="#{galaxyCardPrivilegeBean.status1Show}" style="width:100%" rendered="#{galaxyCardPrivilegeBean.isDefaultBusiness()}"/>

                    <p:outputLabel for="status1Target" value="跳转链接" rendered="#{galaxyCardPrivilegeBean.isDefaultBusiness()}"/>
                    <p:inputText id="status1Target" value="#{galaxyCardPrivilegeBean.status1Target}" style="width:100%" rendered="#{galaxyCardPrivilegeBean.isDefaultBusiness()}"/>
                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:commandButton value="确定添加" actionListener="#{galaxyCardPrivilegeBean.onAddPrivilege()}" process="addPrivilege" update="@form" />
                </div>
            </p:dialog>

            <p:dialog id="editPrivilege" rendered="#{galaxyCardPrivilegeBean.selectedPrivilege != null}"
                      header="卡权益编辑" position="center" widgetVar="editPrivilege" modal="true" width="85%"
                      height="90%" responsive="true" footer="权益类型创建后将无法修改，权益排序的修改需要保证该分类下的所有权益排序等差为1">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="editPrivilegeId" value="权益编号"/>
                    <p:inputText id="editPrivilegeId" value="#{galaxyCardPrivilegeBean.selectedPrivilege.id}" disabled="true" style="width:100%"/>
                    <p:outputLabel for="editPrivilegeType" value="权益分类"/>
                    <p:selectOneMenu id="editPrivilegeType" value="#{galaxyCardPrivilegeBean.selectedPrivilege.privilegeType}" >
                        <f:selectItems value="#{galaxyCardPrivilegeBean.privilegeTypeList}"/>
                    </p:selectOneMenu>
                    <p:outputLabel for="editPrivilegeCode" value="权益类型"/>
                    <p:selectOneMenu id="editPrivilegeCode" value="#{galaxyCardPrivilegeBean.selectedPrivilege.code}" disabled="true">
                        <f:selectItems value="#{galaxyCardPrivilegeBean.privilegeCodeList}"/>
                    </p:selectOneMenu>
                    <p:outputLabel for="editPrivilegeConfig" value="权益配置"/>
                    <p:inputText id="editPrivilegeConfig" value="#{galaxyCardPrivilegeBean.selectedPrivilege.config}" style="width:100%"/>

                    <p:outputLabel for="editPrivilegeName" value="权益名称"/>
                    <p:inputText id="editPrivilegeName" value="#{galaxyCardPrivilegeBean.selectedPrivilege.name}" style="width:100%"/>
                    <p:outputLabel for="editPrivilegeProjectName" value="权益项目"/>
                    <p:inputText id="editPrivilegeProjectName" value="#{galaxyCardPrivilegeBean.selectedPrivilege.projectName}" style="width:100%"/>
                    <p:outputLabel for="editPrivilegeIconUrl" value="权益图标"/>
                    <p:inputText id="editPrivilegeIconUrl" value="#{galaxyCardPrivilegeBean.selectedPrivilege.iconUrl}" style="width:100%"/>
                    <p:outputLabel for="editPrivilegeSort" value="权益排序"/>
                    <p:inputText id="editPrivilegeSort" value="#{galaxyCardPrivilegeBean.selectedPrivilege.sort}" style="width:100%"/>
                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:commandButton value="确定编辑" actionListener="#{galaxyCardPrivilegeBean.onEditPrivilege()}"
                                     rendered="#{security:areAllGranted('GALAXY_CARD_PRIVILEGE_EDIT')}"
                                     process="editPrivilege" update="@form" />
                </div>
            </p:dialog>

            <p:dialog id="upPrivilege" rendered="#{galaxyCardPrivilegeBean.selectedPrivilege != null}"
                      header="卡权益上架" position="center" widgetVar="upPrivilege" modal="true" width="85%"
                      height="90%" responsive="true" footer="权益的上下架需要考虑原先用户的权益状态,请勿随便更改,操作前先选择要操作的卡类型">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="upPrivilegeCode" value="选择上架卡型"/>
                    <p:selectOneMenu id="upPrivilegeCode" value="#{galaxyCardPrivilegeBean.selectedCardType}" >
                        <f:selectItems value="#{galaxyCardPrivilegeBean.cardTypeList}"/>
                    </p:selectOneMenu>
                    <p:outputLabel for="upPrivilegeName" value="上架权益名称"/>
                    <p:inputText id="upPrivilegeName" value="#{galaxyCardPrivilegeBean.selectedPrivilege.name}" readonly="true" style="width:100%"/>
                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:commandButton value="确定上架" actionListener="#{galaxyCardPrivilegeBean.onUpPrivilege()}" process="upPrivilege" update="@form" />
                </div>
            </p:dialog>

            <p:dialog id="downPrivilege" rendered="#{galaxyCardPrivilegeBean.selectedPrivilege != null}"
                      header="卡权益下架" position="center" widgetVar="downPrivilege" modal="true" width="85%"
                      height="90%" responsive="true" footer="权益的上下架需要考虑原先用户的权益状态,请勿随便更改,操作前先选择要操作的卡类型">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="downPrivilegeCode" value="选择下架卡型"/>
                    <p:selectOneMenu id="downPrivilegeCode" value="#{galaxyCardPrivilegeBean.selectedCardType}" >
                        <f:selectItems value="#{galaxyCardPrivilegeBean.cardTypeList}"/>
                    </p:selectOneMenu>
                    <p:outputLabel for="downPrivilegeName" value="下架权益名称"/>
                    <p:inputText id="downPrivilegeName" value="#{galaxyCardPrivilegeBean.selectedPrivilege.name}" readonly="true" style="width:100%"/>
                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:commandButton value="确定下架" actionListener="#{galaxyCardPrivilegeBean.onDownPrivilege()}" process="downPrivilege" update="@form" />
                </div>
            </p:dialog>

            <p:defaultCommand target="search"/>
            <div class="topbar clearfix" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>
                        <p:columnToggler datasource="galaxyCardPrivilegeDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         rendered="#{galaxyCardPrivilegeBean.isNormal()}"
                                         update="@form"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         rendered="#{galaxyCardPrivilegeBean.isNormal()}"
                                         actionListener="#{galaxyCardPrivilegeBean.onReset}"
                                         process="@this" update="@form"/>
                        <p:commandButton icon="fa fa-plus" value="新增权益"
                                         rendered="#{security:areAllGranted('GALAXY_CARD_PRIVILEGE_ADD')}"
                                         oncomplete="PF('addPrivilege').show()"/>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>查询条件</h1>
                            <p:panelGrid columns="8" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-2"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;text-align:center;">
                                <p:outputLabel for="privilegeName" value="权益名称"/>
                                <p:inputText id="privilegeName" value="#{galaxyCardPrivilegeBean.$.privilegeName}"/>

                                <p:outputLabel for="privilegeType" value="权益分类"/>
                                <p:selectOneMenu id="privilegeType" value="#{galaxyCardPrivilegeBean.$.privilegeType}">
                                    <f:selectItem itemLabel="请选择" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{galaxyCardPrivilegeBean.privilegeTypeList}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="privilegeCode" value="权益类型"/>
                                <p:selectOneMenu id="privilegeCode" value="#{galaxyCardPrivilegeBean.$.privilegeCode}">
                                    <f:selectItem itemLabel="请选择" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{galaxyCardPrivilegeBean.privilegeCodeList}"/>
                                </p:selectOneMenu>

                            </p:panelGrid>
                        </div>
                        <div class="card">
                            <p:dataTable id="galaxyCardPrivilegeDataTable"
                                         style="width: 100%;text-align:center"
                                         var="privilege"
                                         value="#{galaxyCardPrivilegeBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         reflow="true"
                                         selection="#{galaxyCardPrivilegeBean.selectedRecords}"
                                         resizableColumns="true">

                                <p:column headerText="操作" style="width:70px;" rendered="#{security:areAllGranted('GALAXY_CARD_PRIVILEGE_OPERATE')}">
                                    <p:splitButton icon="fa fa-pencil"
                                                   actionListener="#{galaxyCardPrivilegeBean.onSelect(privilege)}"
                                                   oncomplete="PF('editPrivilege').show()"
                                                   process="@this" update="@form">
                                        <p:menuitem value="权益上架" icon="fa fa-arrow-up"
                                                    rendered="#{security:areAllGranted('GALAXY_CARD_PRIVILEGE_UP') and privilege.status == 0}"
                                                    actionListener="#{galaxyCardPrivilegeBean.onSelect(privilege)}"
                                                    oncomplete="PF('upPrivilege').show()"
                                                    process="@this" update="@form"/>
                                        <p:menuitem value="权益下架" icon="fa fa-arrow-down"
                                                    rendered="#{security:areAllGranted('GALAXY_CARD_PRIVILEGE_DOWN') and privilege.status == 1}"
                                                    actionListener="#{galaxyCardPrivilegeBean.onSelect(privilege)}"
                                                    oncomplete="PF('downPrivilege').show()"
                                                    process="@this" update="@form"/>
                                        <p:menuitem value="权益状态" icon="fa fa-cube"
                                                    rendered="#{security:areAllGranted('GALAXY_CARD_PRIVILEGE_VIEW_STATUS')}"
                                                    action="#{galaxyCardPrivilegeBean.onShowStatus(privilege.pk)}"
                                                    process="@this">
                                            <f:setPropertyActionListener value="/views/galaxycard/galaxy-card-privilege-list.xhtml"
                                                                         target="#{currentUserBean.back}"/>
                                        </p:menuitem>
                                    </p:splitButton>
                                </p:column>
                                <p:column headerText="ID">
                                    <h:outputText value="#{privilege.pk}"/>
                                </p:column>
                                <p:column headerText="权益分类" style="text-align:center;">
                                    <h:outputText value="#{privilege.type}"/>
                                </p:column>
                                <p:column headerText="权益类别" style="text-align:center;">
                                    <h:outputText value="#{privilege.code}"/>
                                </p:column>
                                <p:column headerText="权益名称" style="text-align:center;">
                                    <h:outputText value="#{privilege.name}"/>
                                </p:column>
                                 <p:column headerText="权益状态" style="text-align:center;">
                                    <h:outputText value="#{galaxyCardPrivilegeBean.translate(DictionaryCode.GALAXY_CARD_PRIVILEGE_STATUS, privilege.status)}"/>
                                </p:column>
                                <p:column headerText="权益排序" style="text-align:center;">
                                    <h:outputText value="#{privilege.sort}"/>
                                </p:column>
                                <p:column headerText="创建时间" style="text-align:center;">
                                    <h:outputText value="#{privilege.createTime}"/>
                                </p:column>
                                <p:column headerText="图标链接" style="text-align:center;">
                                    <h:outputText value="#{privilege.iconUrl}"/>
                                </p:column>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>